#include <myheader.h>
#define FIFO_NAME_FILE "fifo_name_file"
/*Usage: 进程2，通过管道将文件进行创建，并将文件内容进行复制 */
int main(int argc, char *argv[])
{
    //扫描储存管道文件
    int pipe_name_file_fd = open(FIFO_NAME_FILE,O_RDONLY);
    ERROR_CHECK(pipe_name_file_fd,-1,"open_fifo_name_file");
    //将名称读出来
    char pipe_name[60] = {0};
    int read_cnt = read(pipe_name_file_fd,pipe_name,sizeof(pipe_name));
    printf("%d,%s\n",read_cnt,pipe_name);
    ERROR_CHECK(read_cnt,-1,"read_fifo_name_file");
   //打开管道
    int r_pipe_fd = open(pipe_name,O_RDONLY);
    ERROR_CHECK(r_pipe_fd,-1,"open_pipe");
    //将管道内容读出
    //设置buf储存读出管道内容
    char buf[60] = {0};
    int read_pipe_cnt = read(r_pipe_fd,buf,sizeof(buf));
    ERROR_CHECK(read_pipe_cnt,0,"write_close"); 
    ERROR_CHECK(read_pipe_cnt,-1,"read_pipe");
    //创建文件
    int open_file_fd = open(buf,O_RDWR | O_CREAT,0664);
    ERROR_CHECK(open_file_fd,-1,"create_file_by_name");

    close(open_file_fd);
    close(r_pipe_fd);
    close(pipe_name_file_fd);
   
    return 0;
}

